<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>修改密码</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#oldPassword").focus();
			$("#inputForm").validate({
				rules: {
					newPassword:{newIsNotNull:true,code:true,newLength:true}, 
					oldPassword:{yzPassword:true,yzIsNotNull:true},
					confirmNewPassword:{confirmIsNotNull:true},
				},
				messages: {
					newPassword: {equalTo: "两次输入密码不一致"}
				},
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});

			jQuery.validator.addMethod("code", function(value, element) {
				return this.optional(element) || /^(?![^a-zA-Z]+$)(?!\D+$).{8,20}$/.test(value);
			}, "请输入8-20个字符，必须包含字母和数字!");
			
			jQuery.validator.addMethod("yzPassword", function(value,  
	                element, param) { 
				   var stg=$("#stgs").val();
				   if(stg==1){
					   return false;
				   }else{
					   return true;
				   }
				    
	        }, $.validator.format("原密码输入错误！"));
			jQuery.validator.addMethod("yzIsNotNull", function(value,  
	                element, param) { 
				   if($('#oldPassword').val()!=null&&$('#oldPassword').val()!=""){
					   return true;
				   }else{
					   return false;
				   }
				    
	        }, $.validator.format("请输入原密码"));
			
			jQuery.validator.addMethod("newIsNotNull", function(value,  
	                element, param) { 
				   if($('#newPassword').val()!=null&&$('#newPassword').val()!=""){
					   return true;
				   }else{
					   return false;
				   }
				    
	        }, $.validator.format("请输入新密码"));
			
			jQuery.validator.addMethod("newLength", function(value,  
	                element, param) { 
				   if($('#newPassword').val().length>20||$('#newPassword').val().length<8){
					   return false;
				   }else{
					   return true;
				   }
				    
	        }, $.validator.format("请输入8-20个字符，必须包含字母和数字!"));
			
			jQuery.validator.addMethod("confirmIsNotNull", function(value,  
	                element, param) { 
				   if($('#confirmNewPassword').val()!=null&&$('#confirmNewPassword').val()!=""){
					   return true;
				   }else{
					   return false;
				   }
				    
	        }, $.validator.format("请再次输入新密码"));
			
		});
		
		function yzPassword(){
			var oldPassword=$("#oldPassword").val();
			 $.ajax({
			    	type:"post",
			    	data:{"oldPassword":oldPassword},
			    	dataType:"json",
			    	url:"${ctx}/sys/yongUser/yzPassword",
			    	success:function(data){
			    		if(data.stg==1){
			    			$("#stgs").val(1)
			    		}else{
			    			$("#stgs").val(0)
			    		}
			    	}
			    })
		}
		
	</script>
</head>
<body>
      <input name="stgs" id="stgs" type="hidden"/>
	<ul class="nav nav-tabs">
		<%-- <li><a href="${ctx}/sys/user/info">个人信息</a></li> --%>
		<li class="active"><a href="${ctx}/sys/yongUser/updateView">修改密码</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="user" action="${ctx}/sys/yongUser/modifyPwd" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<div style="display:none;">
			<sys:message content="${message}" />
		</div>
		<div class="control-group">
			<label class="control-label">原密码:</label>
			<div class="controls">
				<input id="oldPassword" name="oldPassword" type="password" value="" maxlength="20" minlength="2" onchange="yzPassword()"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">新密码:</label>
			<div class="controls">
				<input id="newPassword" name="newPassword" type="password" />
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">确认新密码:</label>
			<div class="controls">
				<input id="confirmNewPassword" name="confirmNewPassword" type="password" value=""  equalTo="#newPassword"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="修改"/>
			<input id="btnCancel" class="btn" type="button" value="取消" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>